
/**
 * @class Extmx.grid.CheckboxColumn
 * @extends Ext.grid.Column
 * @author Crysfel Villa
 * This class allow you to add a Checkbox in the header of the column
 */

Ext.ns("Bleext.ux.grid");

Extmx.grid.CheckboxColumn = Ext.extend(Ext.grid.Column, {
	checked		: false,
	
    constructor	: function(options) {
        Extmx.grid.CheckboxColumn.superclass.constructor.apply(this, arguments);
		
		
		this.header = String.format('<div class="x-grid3-check-title x-grid3-check-col{0}">&#160;</div>', this.checked ? '-on' : '')+this.header;

		if(this.grid && !this.grid.clickevent){
			this.grid.checkbox = [];
			this.grid.values = [];
			this.grid.indexed = [];
			this.grid.on("headerclick",this.onCellClick,this);
			this.grid.clickevent = true;
		}
		
    },

	onCellClick	: function(grid,columnIndex,event){
		var dom = event.getTarget();

		var chk = this.grid.checkbox[columnIndex];
		if(!chk){
			if(Ext.fly(dom).hasClass("x-grid3-check-title")){
				chk = Ext.get(dom);
				this.grid.checkbox[columnIndex] = chk;
				this.grid.indexed.push(columnIndex);
			}
		}
		
		if(chk && Ext.fly(dom).hasClass("x-grid3-check-title")){
			this.grid.values[columnIndex] = !this.grid.values[columnIndex];
			chk.removeClass("x-grid3-check-col");
			chk.removeClass("x-grid3-check-col-on");
			chk.addClass(String.format('x-grid3-check-col{0}', this.grid.values[columnIndex] ? '-on' : ''));
		}
	}
});

Ext.grid.Column.types.checkboxcolumn = Extmx.grid.CheckboxColumn;